﻿using System;
public class Node<T>
{
    public T Data { get; set; }
    public Node<T> Next { get; set; }

    public Node(T data)
    {
        Data = data;
        Next = null;
    }
}
public class GenericLinkedList<T>
{
    private Node<T> head;

    public void Add(T data)
    {
        Node<T> newNode = new Node<T>(data);
        if (head == null)
        {
            head = newNode;
        }
        else
        {
            Node<T> current = head;
            while (current.Next != null)
            {
                current = current.Next;
            }
            current.Next = newNode;
        }
    }
    public void ForEach(Action<T> action)
    {
        Node<T> current = head;
        while (current != null)
        {
            action(current.Data);
            current = current.Next;
        }
    }
}
class Program
{
    static void Main()
    {
        GenericLinkedList<int> list = new GenericLinkedList<int>();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        list.Add(5);

        Console.WriteLine("链表元素:");
        list.ForEach(x => Console.Write(x + " "));
        Console.WriteLine();

        int max = int.MinValue;
        list.ForEach(x => max = Math.Max(max, x));
        Console.WriteLine("最大值: " + max);

        int min = int.MaxValue;
        list.ForEach(x => min = Math.Min(min, x));
        Console.WriteLine("最小值: " + min);

        int sum = 0;
        list.ForEach(x => sum += x);
        Console.WriteLine("总和: " + sum);
    }
}